﻿using System.Collections.Generic;

namespace PnFramework
{
    public class LoopList<T>
    {
        private List<T> list;
        /// <summary>
        /// 游标 会动的下标
        /// </summary>
        private int mVernier;
        public int Vernier => mVernier;
        /// <summary>
        /// 列表个数
        /// </summary>
        public int Count => list.Count;
        /// <summary>
        /// 构造函数
        /// </summary>
        public LoopList() => list = new List<T>();
        public LoopList(IEnumerable<T> e) => list = new List<T>(e);
        /// <summary>
        /// 正向循环
        /// </summary>
        public void LoopPos() => mVernier = ++mVernier % list.Count;
        /// <summary>
        /// 负向循环
        /// </summary>
        public void LoopNeg() => mVernier = (list.Count - 1 + mVernier) % list.Count;
        /// <summary>
        /// 向游标位置添加元素
        /// </summary>
        public void Insert(T e) => list.Insert(mVernier, e);
        public void AddLast(T e) => list.Add(e);
        /// <summary>
        /// 获取游标位置
        /// </summary>
        public T Get() => list[mVernier];
        public T Get(int index) => list[index];
    }
}
